﻿using System;
using System.Globalization;
using System.Windows.Data;

namespace RytmSerca.Converters
{
    public class MultiplyingConverter : IValueConverter
    {
        private static readonly IValueConverter instance = new MultiplyingConverter();

        public static IValueConverter Instance
        {
            get { return instance; }
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (parameter is string)
                parameter = double.Parse(parameter.ToString(), CultureInfo.InvariantCulture);
            if (value is string)
                value = double.Parse(value.ToString());
            if (parameter is int)
                parameter = (double) (int) parameter;
            if (value is int)
                value = (double)(int)value;
            return (double) value*(double) parameter;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
}